package com.server.controller;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import com.server.common.base.PathManager;
import com.server.common.base.SessionData;
import com.server.common.util.JSONUtil4TSY;
import com.server.service.IAttachmentService;
import com.server.service.ICommonDataService;
import com.server.service.ILoginService;
import com.server.service.IMonthStatisticService;
import com.server.service.IOrgManagementService;
import com.server.service.IReferralService;
import com.server.service.ISourceService;
import com.server.service.IUserManagementService;
import com.server.web.DataVector;
import com.server.web.JSONSerielizer;
import com.server.web.OutputUtil;
import com.server.web.RequestInput;
import com.server.web.SessionUtil;

@Controller
@RequestMapping("app")
public class AppController {

	private static final String VIEW_NAME = "reward.v_user_employ";

	@Autowired
	private IReferralService referralService;
	@Autowired
	private IUserManagementService userManagementService;
	@Autowired
	private IMonthStatisticService monthStatisticService;
	@Autowired
	private ICommonDataService commonDataService;
	@Autowired
	private IOrgManagementService orgManagementService;
	@Autowired
	private ILoginService loginService;
	@Autowired
	private IAttachmentService attachmentService;
	@Autowired
	private ISourceService sourceService;

	@RequestMapping("verify")
	public void verify(HttpServletRequest request, HttpServletResponse response,
			HttpSession session) {
		String name = request.getParameter("username");
		String password = request.getParameter("password");
		Boolean isSuccess = false;
		String info = null;
		
		Integer levle = 0;

		Map<String, Object> map = new HashMap<String, Object>();

		Map<String, Object> login = loginService.Login(name, password);
		String cardId = "";
		String userName = "";
		if (login != null && login.size() > 0
				&& (Boolean) login.get("isSuccess")) {
			Object cardObj = login.get("CardID");
			if (cardObj != null) {
				cardId = cardObj.toString();
			}
			Object userObj = login.get("UserName");
			if (userObj != null) {
				userName = userObj.toString();
			}
			SessionUtil.setSession(request, SessionData.nameKey, userName);
			SessionUtil.setSession(request, SessionData.loginNameKey,
					login.get("LoginName"));
			SessionUtil.setSession(request, SessionData.cardIdKey, cardId);
			levle = Integer.parseInt(login.get("Manager").toString());
			SessionUtil.setSession(request, SessionData.levelKey,
					levle);

			isSuccess = true;
			info = "登陆成功！";
			map.put("isSuccess", isSuccess);
			map.put("info", info);
		} else {
			isSuccess = false;
			info = "用户名或密码错误！";
			map.put("isSuccess", isSuccess);
			map.put("info", info);
		}
		response.addHeader("Access-Control-Allow-Origin",
				request.getHeader("Origin"));
		response.addHeader("Access-Control-Allow-Credentials", "true");
		response.addHeader("Content-Type", "application/json; charset=utf-8");
		String map2Json = JSONUtil4TSY.map2Json(levle,map, cardId, userName,
				response.getStatus(), "");
		OutputUtil.returnString(response, map2Json);
	}
	@RequestMapping("logout")
	public void logout(HttpServletRequest request,HttpServletResponse response){
		 SessionUtil.clear(request);
		 response.addHeader("Access-Control-Allow-Origin",
				 request.getHeader("Origin"));
		 response.addHeader("Access-Control-Allow-Credentials", "true");
		 response.addHeader("Content-Type", "application/json; charset=utf-8");
		 String str2Json = JSONUtil4TSY.str2Json(0, "true", "", "", response.getStatus(), "");
		 OutputUtil.returnString(response, str2Json);
	}

	/**
	 * 所有人员列表
	 * 
	 * @param request
	 * @param response
	 * @param orgNo
	 * @param state
	 * @author ServerZhang
	 * @date 2017年3月18日
	 */
	@RequestMapping("user/list/{orgNo}/{state}")
	public void userList(HttpServletRequest request,
			HttpServletResponse response, @PathVariable String orgNo,
			@PathVariable Integer state) {
		String cardId = SessionUtil.getStringAttri(request,
				SessionData.cardIdKey);
		String userName = SessionUtil.getStringAttri(request,
				SessionData.nameKey);
		Integer level = SessionUtil.getIntAttri(request,
				SessionData.levelKey);
		String errInfor = "";
		if (StringUtils.isEmpty(cardId) || StringUtils.isEmpty(userName)) {
			errInfor = "未登录";
		}
		response.addHeader("Access-Control-Allow-Origin",
				request.getHeader("Origin"));
		response.addHeader("Access-Control-Allow-Credentials", "true");
		response.addHeader("Content-Type", "application/json; charset=utf-8");
		Integer levelKey = SessionUtil.getIntAttri(request,
				SessionData.levelKey);
		RequestInput requestInput = new RequestInput(request);
		DataVector<Map<String, Object>> listData = userManagementService
				.getList(requestInput, orgNo, state, levelKey);
		String list2Json = JSONUtil4TSY.list2Json(level,listData.getList(),
				listData.getCount(), requestInput.getPageSize(),
				requestInput.getPageIndex() + 1, cardId, userName,
				response.getStatus(), "");
		OutputUtil.returnString(response, list2Json);
	}

	/**
	 * 我招聘的人员列表
	 * 
	 * @param request
	 * @param response
	 * @param state
	 * @author ServerZhang
	 * @date 2017年3月18日
	 */
	@RequestMapping("referral/list/{state}")
	public void referralList(HttpServletRequest request,
			HttpServletResponse response, @PathVariable Integer state) {
		String cardId = SessionUtil.getStringAttri(request,
				SessionData.cardIdKey);
		String userName = SessionUtil.getStringAttri(request,
				SessionData.nameKey);
		Integer level = SessionUtil.getIntAttri(request,
				SessionData.levelKey);
		String errInfor = "";
		if (StringUtils.isEmpty(cardId) || StringUtils.isEmpty(userName)) {
			errInfor = "未登录";
		}

		response.addHeader("Access-Control-Allow-Origin",
				request.getHeader("Origin"));
		response.addHeader("Access-Control-Allow-Credentials", "true");
		response.addHeader("Content-Type", "application/json; charset=utf-8");
		RequestInput requestInput = new RequestInput(request);
		DataVector<Map<String, Object>> listData = referralService.getList(
				requestInput, state, cardId);
		String list2Json = JSONUtil4TSY.list2Json(level,listData.getList(),
				listData.getCount(), requestInput.getPageSize(),
				requestInput.getPageIndex() + 1, cardId, userName,
				response.getStatus(), errInfor);
		OutputUtil.returnString(response, list2Json);
	}

	/**
	 * 人员详细
	 * 
	 * @param request
	 * @param response
	 * @param employId
	 * @author ServerZhang
	 * @date 2017年3月18日
	 */
	@RequestMapping("user/form/{employId}")
	public void userForm(HttpServletRequest request,
			HttpServletResponse response, @PathVariable String employId) {
		String cardId = SessionUtil.getStringAttri(request,
				SessionData.cardIdKey);
		String userName = SessionUtil.getStringAttri(request,
				SessionData.nameKey);
		Integer level = SessionUtil.getIntAttri(request,
				SessionData.levelKey);
		String errInfor = "";
		if (StringUtils.isEmpty(cardId) || StringUtils.isEmpty(userName)) {
			errInfor = "未登录";
		}

		response.addHeader("Access-Control-Allow-Origin",
				request.getHeader("Origin"));
		response.addHeader("Access-Control-Allow-Credentials", "true");
		response.addHeader("Content-Type", "application/json; charset=utf-8");
		Map<String, Object> form = userManagementService.getForm(employId);
		String map2Json = JSONUtil4TSY.map2Json(level,form, cardId, userName,
				response.getStatus(), errInfor);
		OutputUtil.returnString(response, map2Json);
	}

	/**
	 * 个人资料
	 * 
	 * @param request
	 * @param response
	 * @author ServerZhang
	 * @date 2017年3月18日
	 */
	@RequestMapping("user/infor")
	public void userInfor(HttpServletRequest request, HttpServletResponse response) {
		String cardId = SessionUtil.getStringAttri(request,
				SessionData.cardIdKey);
		String userName = SessionUtil.getStringAttri(request,
				SessionData.nameKey);
		Integer level = SessionUtil.getIntAttri(request,
				SessionData.levelKey);
		String errInfor = "";
		if (StringUtils.isEmpty(cardId) || StringUtils.isEmpty(userName)) {
			errInfor = "未登录";
		}
		response.addHeader("Access-Control-Allow-Origin",
				request.getHeader("Origin"));
		response.addHeader("Access-Control-Allow-Credentials", "true");
		response.addHeader("Content-Type", "application/json; charset=utf-8");
		Map<String, Object> formData = commonDataService.getFormData(VIEW_NAME,
				"CardID", cardId, "State=1", null);
		String map2Json = JSONUtil4TSY.map2Json(level,formData, cardId, userName,
				response.getStatus(), errInfor);
		OutputUtil.returnString(response, map2Json);
	}

	/**
	 * 
	 * @param request
	 * @param response
	 * @param start
	 * @param end
	 * @author ServerZhang
	 * @date 2017年3月18日
	 */
	@RequestMapping("income/list")
	public void incomeList(HttpServletRequest request,
			HttpServletResponse response) {
		String cardId = SessionUtil.getStringAttri(request,
				SessionData.cardIdKey);
		String userName = SessionUtil.getStringAttri(request,
				SessionData.nameKey);
		Integer level = SessionUtil.getIntAttri(request,
				SessionData.levelKey);
		String errInfor = "";
		if (StringUtils.isEmpty(cardId) || StringUtils.isEmpty(userName)) {
			errInfor = "未登录";
		}
		response.addHeader("Access-Control-Allow-Origin",
				request.getHeader("Origin"));
		response.addHeader("Access-Control-Allow-Credentials", "true");
		response.addHeader("Content-Type", "application/json; charset=utf-8");
		RequestInput requestInput = new RequestInput(request);
		DataVector<Map<String, Object>> listData = monthStatisticService
				.getList(requestInput, cardId, null, null);
		String list2Json = JSONUtil4TSY.list2Json(level,listData.getList(),
				listData.getCount(), requestInput.getPageSize(),
				requestInput.getPageIndex() + 1, cardId, userName,
				response.getStatus(), errInfor);
		OutputUtil.returnString(response, list2Json);
	}

	/**
	 * 月份区间
	 * 
	 * @param request
	 * @param response
	 * @author ServerZhang
	 * @date 2017年3月18日
	 */
	@RequestMapping("period")
	public void period(HttpServletRequest request, HttpServletResponse response) {
		String cardId = SessionUtil.getStringAttri(request,
				SessionData.cardIdKey);
		String userName = SessionUtil.getStringAttri(request,
				SessionData.nameKey);
		Integer level = SessionUtil.getIntAttri(request,
				SessionData.levelKey);
		String errInfor = "";
		if (StringUtils.isEmpty(cardId) || StringUtils.isEmpty(userName)) {
			errInfor = "未登录";
		}
		response.addHeader("Access-Control-Allow-Origin",
				request.getHeader("Origin"));
		response.addHeader("Access-Control-Allow-Credentials", "true");
		response.addHeader("Content-Type", "application/json; charset=utf-8");
		RequestInput requestInput = new RequestInput(request);
		List<Map<String, Object>> period = monthStatisticService
				.getPeriod(cardId);
		String list2Json = JSONUtil4TSY.list2Json(level,period, period.size(),
				requestInput.getPageSize(), requestInput.getPageIndex() + 1,
				cardId, userName, response.getStatus(), errInfor);
		OutputUtil.returnString(response, list2Json);
	}

	/**
	 * 企业列表
	 * 
	 * @param request
	 * @param response
	 * @author ServerZhang
	 * @date 2017年3月18日
	 */
	@RequestMapping("org/list")
	public void orgList(HttpServletRequest request, HttpServletResponse response) {
		String cardId = SessionUtil.getStringAttri(request,
				SessionData.cardIdKey);
		String userName = SessionUtil.getStringAttri(request,
				SessionData.nameKey);
		Integer level = SessionUtil.getIntAttri(request,
				SessionData.levelKey);
		String errInfor = "";
		response.addHeader("Access-Control-Allow-Origin",
				request.getHeader("Origin"));
		response.addHeader("Access-Control-Allow-Credentials", "true");
		response.addHeader("Content-Type", "application/json; charset=utf-8");
		RequestInput requestInput = new RequestInput(request);
		DataVector<Map<String, Object>> listData = orgManagementService
				.getList(requestInput);
		
		StringBuffer serverBuffer = new StringBuffer();
		String serverName = request.getServerName();
		int serverPort = request.getServerPort();
		serverBuffer.append("http://").append(serverName)
			.append(":").append(serverPort).append("/")
			.append(PathManager.FILE_MAPPING);
		
		List<Map<String, Object>> list = listData.getList();
		Iterator<Map<String, Object>> iterator = list.iterator();
		while(iterator.hasNext()){
			Map<String, Object> next = iterator.next();
			Object webObj = next.get("OrgWeb");
			Object imgObj = next.get("OrgImg");
			Object linkObj = next.get("EmployLink");
			if (imgObj != null) {
				next.put("ImgUrl", serverBuffer.toString()+imgObj.toString());
			}
			if (webObj != null) {
				String webSite = webObj.toString();
				if (!webSite.startsWith("http://")) {
					webSite = "http://"+webSite;
				}
				next.put("OrgWeb", webSite);
			}
			if (linkObj != null) {
				String link = linkObj.toString();
				if (!link.startsWith("http://")) {
					link = "http://"+link;
				}
				next.put("EmployLinkUrl", link);
			}
		}
		
		String list2Json = JSONUtil4TSY.list2Json(level,list,
				listData.getCount(), requestInput.getPageSize(),
				requestInput.getPageIndex() + 1, cardId, userName,
				response.getStatus(), errInfor);
		OutputUtil.returnString(response, list2Json);
	}

	@RequestMapping("org/form/{orgNo}")
	public void orgForm(HttpServletRequest request,
			HttpServletResponse response, @PathVariable String orgNo) {
		String cardId = SessionUtil.getStringAttri(request,
				SessionData.cardIdKey);
		String userName = SessionUtil.getStringAttri(request,
				SessionData.nameKey);
		Integer level = SessionUtil.getIntAttri(request,
				SessionData.levelKey);
		String errInfor = "";
		if (StringUtils.isEmpty(cardId) || StringUtils.isEmpty(userName)) {
			errInfor = "未登录";
		}
		response.addHeader("Access-Control-Allow-Origin",
				request.getHeader("Origin"));
		response.addHeader("Access-Control-Allow-Credentials", "true");
		response.addHeader("Content-Type", "application/json; charset=utf-8");
		Map<String, Object> formData = orgManagementService.getForm(orgNo);
		String map2Json = JSONUtil4TSY.map2Json(level,formData, cardId, userName,
				response.getStatus(), errInfor);
		OutputUtil.returnString(response, map2Json);
	}

	/**
	 * 入职及信息修改
	 * 
	 * @param request
	 * @param response
	 * @param action
	 * @author ServerZhang
	 * @date 2017年3月18日
	 */
	@RequestMapping("user/save/{action}")
	public void userSave(HttpServletRequest request,
			HttpServletResponse response, @PathVariable String action) {
		String cardId = SessionUtil.getStringAttri(request,
				SessionData.cardIdKey);
		String userName = SessionUtil.getStringAttri(request,
				SessionData.nameKey);
		Integer level = SessionUtil.getIntAttri(request,
				SessionData.levelKey);
		String errInfor = "";
		if (StringUtils.isEmpty(cardId) || StringUtils.isEmpty(userName)) {
			errInfor = "未登录";
		}
		response.addHeader("Access-Control-Allow-Origin",
				request.getHeader("Origin"));
		response.addHeader("Access-Control-Allow-Credentials", "true");
		response.addHeader("Content-Type", "application/json; charset=utf-8");
		String formData = request.getParameter("formData");
		Map<String, Object> inputMap = JSONSerielizer.toMap(formData);

		Map<String, Object> map = userManagementService.addAndEmploy(cardId,
				inputMap, action);
		String map2Json = JSONUtil4TSY.map2Json(level,map, cardId, userName,
				response.getStatus(), errInfor);
		OutputUtil.returnString(response, map2Json);
	}

	/**
	 * 来源列表
	 * 
	 * @param request
	 * @param response
	 * @param typeId
	 * @author ServerZhang
	 * @date 2017年3月18日
	 */
	@RequestMapping("source/{typeId}")
	public void source(HttpServletRequest request,
			HttpServletResponse response, @PathVariable Integer typeId) {
		String cardId = SessionUtil.getStringAttri(request,
				SessionData.cardIdKey);
		String userName = SessionUtil.getStringAttri(request,
				SessionData.nameKey);
		Integer level = SessionUtil.getIntAttri(request,
				SessionData.levelKey);
		String errInfor = "";
		if (StringUtils.isEmpty(cardId) || StringUtils.isEmpty(userName)) {
			errInfor = "未登录";
		}
		response.addHeader("Access-Control-Allow-Origin",
				request.getHeader("Origin"));
		response.addHeader("Access-Control-Allow-Credentials", "true");
		response.addHeader("Content-Type", "application/json; charset=utf-8");
		RequestInput requestInput = new RequestInput(request);
		DataVector<Map<String, Object>> listData = sourceService.getList(requestInput, typeId);
		List<Map<String, Object>> list = listData.getList();
		Iterator<Map<String, Object>> iterator = list.iterator();
		while(iterator.hasNext()){
			Map<String, Object> next = iterator.next();
			Object nameObj = next.get("UserName");
			Object phoneObj = next.get("PhoneNo");
			if (nameObj != null && phoneObj != null) {
				next.put("UserName", nameObj.toString()+"（"+phoneObj.toString()+"）");
			}
			
		}
		String list2Json = JSONUtil4TSY.list2Json(level,list, listData.getCount(), 0,
				0, cardId, userName, response.getStatus(), errInfor);
		OutputUtil.returnString(response, list2Json);
		
		OutputUtil.returnGridData(response, listData.getCount(), JSONSerielizer.toJson(listData.getList(), null, null));
	}

	/**
	 * 其他信息串
	 * 
	 * @param request
	 * @param response
	 * @author ServerZhang
	 * @date 2017年3月18日
	 */
	@RequestMapping("others")
	public void others(HttpServletRequest request, HttpServletResponse response) {
		String cardId = SessionUtil.getStringAttri(request,
				SessionData.cardIdKey);
		String userName = SessionUtil.getStringAttri(request,
				SessionData.nameKey);
		Integer level = SessionUtil.getIntAttri(request,
				SessionData.levelKey);
		String errInfor = "";
		if (StringUtils.isEmpty(cardId) || StringUtils.isEmpty(userName)) {
			errInfor = "未登录";
		}
		response.addHeader("Access-Control-Allow-Origin",
				request.getHeader("Origin"));
		response.addHeader("Access-Control-Allow-Credentials", "true");
		response.addHeader("Content-Type", "application/json; charset=utf-8");

		List<Map<String, Object>> list = userManagementService
				.getConfigStr4App();
		String list2Json = JSONUtil4TSY.list2Json(level,list, list.size(), 0, 0,
				cardId, userName, response.getStatus(), errInfor);
		OutputUtil.returnString(response, list2Json);
	}

	/**
	 * 各种分类列表
	 * 
	 * @param request
	 * @param response
	 * @param category
	 * @author ServerZhang
	 * @date 2017年3月6日
	 */
	@RequestMapping("common/type/{category}")
	public void type(HttpServletRequest request, HttpServletResponse response,
			@PathVariable String category) {
		String cardId = SessionUtil.getStringAttri(request,
				SessionData.cardIdKey);
		String userName = SessionUtil.getStringAttri(request,
				SessionData.nameKey);
		Integer level = SessionUtil.getIntAttri(request,
				SessionData.levelKey);
		String errInfor = "";
		if (StringUtils.isEmpty(cardId) || StringUtils.isEmpty(userName)) {
			errInfor = "未登录";
		}
		response.addHeader("Access-Control-Allow-Origin",
				request.getHeader("Origin"));
		response.addHeader("Access-Control-Allow-Credentials", "true");
		response.addHeader("Content-Type", "application/json; charset=utf-8");
		RequestInput requestInput = new RequestInput(request);
		List<Map<String, Object>> list = commonDataService.getType("reward."
				+ category);

		String list2Json = JSONUtil4TSY.list2Json(level,list, list.size(),
				requestInput.getPageSize(), requestInput.getPageIndex() + 1,
				cardId, userName, response.getStatus(), errInfor);
		OutputUtil.returnString(response, list2Json);
	}
	@RequestMapping("user/employ/{state}")
	public void employ(HttpServletRequest request,
			HttpServletResponse response, @PathVariable Integer state){
		String operator = SessionUtil.getStringAttri(request, SessionData.cardIdKey);
		String userName = SessionUtil.getStringAttri(request,
				SessionData.nameKey);
		Integer level = SessionUtil.getIntAttri(request,
				SessionData.levelKey);
		String errInfor = "";
		if (StringUtils.isEmpty(operator) || StringUtils.isEmpty(userName)) {
			errInfor = "未登录";
		} 
		response.addHeader("Access-Control-Allow-Origin",
				request.getHeader("Origin"));
		response.addHeader("Access-Control-Allow-Credentials", "true");
		response.addHeader("Content-Type", "application/json; charset=utf-8");
		String employIds = request.getParameter("employIds");
		Boolean isSuccess = false;
		if (state.equals(0)) {
			isSuccess = userManagementService.delete(operator,employIds);
		}else if (state.equals(1)) {
			isSuccess = userManagementService.employ(operator,employIds);
		}
		String str2Json = JSONUtil4TSY.str2Json(level,isSuccess.toString(), operator, userName, response.getStatus(), errInfor);
		OutputUtil.returnString(response, str2Json);
	}
	@RequestMapping("user/checkIn")
	public void checkIn(HttpServletRequest request,
			HttpServletResponse response){
		String operator = SessionUtil.getStringAttri(request, SessionData.cardIdKey);
		String employIds = request.getParameter("employIds");
		String dayStr = request.getParameter("days");
		Float days = 0.0F;
		if (!StringUtils.isEmpty(dayStr)) {
			days = Float.parseFloat(dayStr);
		}
		String userName = SessionUtil.getStringAttri(request,
				SessionData.nameKey);
		Integer level = SessionUtil.getIntAttri(request,
				SessionData.levelKey);
		String errInfor = "";
		if (StringUtils.isEmpty(operator) || StringUtils.isEmpty(userName)) {
			errInfor = "未登录";
		} 
		response.addHeader("Access-Control-Allow-Origin",
				request.getHeader("Origin"));
		response.addHeader("Access-Control-Allow-Credentials", "true");
		response.addHeader("Content-Type", "application/json; charset=utf-8");
		Boolean isSuccess = userManagementService.checkIn(operator, employIds, days);
		String str2Json = JSONUtil4TSY.str2Json(level,isSuccess.toString(), operator, userName, response.getStatus(), errInfor);
		OutputUtil.returnString(response, str2Json);
	}
	@RequestMapping("user/checkInList/{employId}")
	public void checkInList(HttpServletRequest request,
			HttpServletResponse response,@PathVariable Integer employId){
		String operator = SessionUtil.getStringAttri(request, SessionData.cardIdKey);
		String userName = SessionUtil.getStringAttri(request,
				SessionData.nameKey);
		Integer level = SessionUtil.getIntAttri(request,
				SessionData.levelKey);
		String errInfor = "";
		if (StringUtils.isEmpty(operator) || StringUtils.isEmpty(userName)) {
			errInfor = "未登录";
		} 
		response.addHeader("Access-Control-Allow-Origin",
				request.getHeader("Origin"));
		response.addHeader("Access-Control-Allow-Credentials", "true");
		response.addHeader("Content-Type", "application/json; charset=utf-8");
		RequestInput requestInput = new RequestInput(request);
		DataVector<Map<String, Object>> listData = userManagementService.getCheckInList(requestInput, employId);
		
		String list2Json = JSONUtil4TSY.list2Json(level,listData.getList(),
				listData.getCount(), requestInput.getPageSize(),
				requestInput.getPageIndex() + 1, operator, userName,
				response.getStatus(), "");
		OutputUtil.returnString(response, list2Json);
	}
	@RequestMapping("user/info/{cardId}")
	public void info(HttpServletRequest request,
			HttpServletResponse response,@PathVariable String cardId){
		String operator = SessionUtil.getStringAttri(request,
				SessionData.cardIdKey);
		String userName = SessionUtil.getStringAttri(request,
				SessionData.nameKey);
		Integer level = SessionUtil.getIntAttri(request,
				SessionData.levelKey);
		String errInfor = "";
		if (StringUtils.isEmpty(cardId) || StringUtils.isEmpty(userName)) {
			errInfor = "未登录";
		}

		response.addHeader("Access-Control-Allow-Origin",
				request.getHeader("Origin"));
		response.addHeader("Access-Control-Allow-Credentials", "true");
		response.addHeader("Content-Type", "application/json; charset=utf-8");
		
		Map<String, Object> form = userManagementService.getFormByCard(cardId);
		String map2Json = JSONUtil4TSY.map2Json(level,form, cardId, userName,
				response.getStatus(), errInfor);
		OutputUtil.returnString(response, map2Json);
	}
	@RequestMapping("org4card/{cardId}")
	public void org4card(HttpServletRequest request,
			HttpServletResponse response,@PathVariable String cardId){
		String operator = SessionUtil.getStringAttri(request,
				SessionData.cardIdKey);
		String userName = SessionUtil.getStringAttri(request,
				SessionData.nameKey);
		Integer level = SessionUtil.getIntAttri(request,
				SessionData.levelKey);
		String errInfor = "";
		if (StringUtils.isEmpty(cardId) || StringUtils.isEmpty(userName)) {
			errInfor = "未登录";
		}
		
		response.addHeader("Access-Control-Allow-Origin",
				request.getHeader("Origin"));
		response.addHeader("Access-Control-Allow-Credentials", "true");
		response.addHeader("Content-Type", "application/json; charset=utf-8");
		
		String orgNo = orgManagementService.getOrg4User(cardId);
		String str2Json = JSONUtil4TSY.str2Json(level,orgNo, cardId, userName,
				response.getStatus(), errInfor);
		OutputUtil.returnString(response, str2Json);
	}

}
